﻿using MiniFox.Data.EntityFramework;
using MiniFox.Platform;

namespace OAuth2.Data
{
    public abstract class BaseOAuth2DataProvider : EntityDataProvider<PlatformDbContext>
    {
        protected OpenAuthIdentity MappingIdentity(SysUser sys_user)
        {
            if (sys_user == null)
                return null;
            OpenAuthIdentity identity = new OpenAuthIdentity(sys_user.UserId);
            identity.Name = sys_user.LoginName;
            identity.SecEmail = sys_user.SecEmail;
            identity.Cellphone = sys_user.Cellphone;
            identity.Status = Enum.Parse<IdentityStatus>(sys_user.UserStatus);
            identity.DisplayName = sys_user.DisplayName;
            identity.Roles = (from r in this.CurrentDbContext.SysUserRole where r.UserId == sys_user.UserId select r.RoleId).ToArray();
            //identity.Icon = sys_user.Icon;
            return identity;
        }

    }
}
